package com.pxmeta.app.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Date;

@Configuration
@EnableSwagger2
@Profile({"dev","local"})
public class Knife4jConfiguration {


    /**
     * swagger配置  路径/doc.html
     * @return
     */
    @Bean(value = "app-api")
    public Docket appApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .directModelSubstitute(LocalDateTime.class, Date.class)
                .directModelSubstitute(LocalDate.class, String.class)
                .directModelSubstitute(LocalTime.class, String.class)
                .directModelSubstitute(ZonedDateTime.class, String.class)
                .apiInfo(new ApiInfoBuilder()
                        //.title("swagger-bootstrap-ui-demo RESTful APIs")
                        .description("为碰心App提供的接口文档")
                        .termsOfServiceUrl("https://api.pengxinmeta.com/")
                        .contact(new Contact("碰心科技", "https://pengxinmeta.com", "weichenglong@pengxinmeta.com"))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("AppAPI")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.pxmeta.app"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
